package com.yong.sbd.biz.mp.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yong.sbd.biz.mp.entity.SysUser;
import com.yong.sbd.biz.mp.mapper.SysUserMapper;
import com.yong.sbd.biz.mp.service.SysUserService;
import com.yong.sbd.common.beans.page.PageParam;
import com.yong.sbd.common.beans.page.PageResult;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户服务实现类
 *
 * @author Kang Yong
 * @date 2025/10/27
 * @since 1.0.0
 */
@Service
@RequiredArgsConstructor
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {

    private final SysUserMapper sysUserMapper;

    @Override
    public PageResult<SysUser> pageData(PageParam pageParam) {
        // 查询（基于苞米豆的分页查询）
        Page<SysUser> page = this.page(Page.of(pageParam.getPageNum(), pageParam.getPageSize()));

        // 封装结果集
        return PageResult.page(pageParam, page.getTotal(), page.getRecords());
    }

    /**
     * 根据用户ID查询用户及其角色信息
     *
     * @param userId 用户ID
     * @return {@link SysUser}
     */
    @Override
    public SysUser getUserWithRoles(Long userId) {
        return sysUserMapper.selectUserWithRoles(userId);
    }

    /**
     * 查询所有用户及其角色信息
     *
     * @return {@link List<SysUser>}
     */
    @Override
    public List<SysUser> getUsersWithRoles() {
        return sysUserMapper.selectUsersWithRoles();
    }
}